<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script   src="https://code.jquery.com/jquery-2.2.4.min.js"   integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="   crossorigin="anonymous"></script>
    </head>
    <body>
        <div>TODO write content</div>
        <input type='button' value='Send msg' onclick="sendMsg();" />
    <script>
        
        var d = new Date();
        var open_id="OPENID_"+d.getTime();
        
    // 假设服务端ip为127.0.0.1
    ws = new WebSocket("ws://hx2.hztc.dev.kaitianad.com:2345");
    ws.onopen = function() {
//        console.log("连接成功");
//        var d = new Date();
//        ws.send('JS-Client:'+d.getTime());
//        console.log("给服务端发送一个字符串：tom");
    };
    ws.onmessage = function(e) {
        console.log("收到服务端的消息：" + e.data);
        // json数据转换成js对象
        var data = eval("("+e.data+")");
        var type = data.type || '';
        switch(type){
            // Events.php中返回的init类型的消息，将client_id发给后台进行uid绑定
            case 'init':
                // 利用jquery发起ajax请求，将client_id发给后端进行uid绑定
                $.post('./bind.php', {client_id: data.client_id,open_id:open_id}, function(data){}, 'json');
                break;
            // 当mvc框架调用GatewayClient发消息时直接alert出来
            default :
                console.log("Not doing");
        }
    };
    </script>
    </body>
</html>